package pkg

import (
	"api/config"
	"github.com/google/uuid"
	"github.com/hashicorp/consul/api"
	"go.uber.org/zap"
)

type Consul struct {
	Host string
	Port int
}

func NewConsul(host string, port int) *Consul {
	return &Consul{
		Host: host,
		Port: port,
	}
}

func (c *Consul) RegisterServer(name, host string, port int, tags []string) {
	a := &api.AgentServiceRegistration{
		ID:      uuid.NewString(),
		Name:    name,
		Tags:    tags,
		Port:    port,
		Address: host,
	}
	err := config.Consul.Agent().ServiceRegister(a)
	if err != nil {
		zap.S().Error(err)
	}
}
